<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
    <h2>天气预报查询</h2>
    <input type="text" placeholder="查询的城市">

    <input type="button" value="查询">


</body>
</html>
<script>
    document.querySelector('input[type=button]').onclick=function(){
        // 创建异步对象
        var xhr = new XMLHttpRequest();

        // 请求
        xhr.open('get','http://wthrcdn.etouch.cn/WeatherApi?city=' + document.querySelector('input[type=text]').value);

        // 判断状态 请求是否成功并使用数据
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
                console.log(xhr.responseXML);
            }
        }

        // 发送请求
        xhr.send(null);
    }
</script>